import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项
import {
    getQualityDutyByFid, //详情
    updateQualityDuty
} from "@/api/request.js";
export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "projectId",
        "status",
        "statusNum",
        "dataFid",
        "currentRow",
        "projectName",
        "fCompanyid"
    ],
    data() {
        return {
            visible: "",
            title: "停用",
            isLock: false, // 控制按钮的disable属性
            btnStatus: [],
            dialogHeight: null,
            activeIndex: "1",
            formObj: formJs.formObj,
            currntData: null,
            dataInfo: null,
            formData: {},

            btnShow: true,
            currentStatus: null,
        };
    },
    components: {
        publicForm,
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },

        statusNum: {
            handler(newVal) {
                if (newVal) {
                    this.edit(newVal);
                }
            },
            immediate: true,
        },
        dataFid: {
            handler(newVal) {
                if (newVal) {
                    console.log(newVal);
                    this.currntData = newVal;
                    if (this.statusNum != 1) {
                        this.formData = this.$options.data.call(this).formData;
                        this.getDetail({
                            fId: newVal,
                        });
                    }
                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentStatus = newVal;
                }
            },
            immediate: true,
        },

    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));

        this.btnShow = true

        this.getDetail({
            fId: this.currentStatus.fId
        })
        this.getHeight();
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        handleSelect(key) {
            this.activeIndex = key;
        },
        closeDialog() {
            this.$emit("close");
        },

        // 详情
        getDetail(data1) {
            getQualityDutyByFid(data1).then((res) => {
                if (res.errcode == 0) {
                    this.formData = res.data.yjQmpMsQualitydutyManagement;

                }

            });
        },

        yj_saveForm() {
            var data = {
                fId: this.formData.fId, //传入表示修改 不传表示新增
                userId: this.userInfo.userId, //当前登录人id    
                userName: this.userInfo.userName, // 当前登录人名称
                fLogoutdates: this.formData.fLogoutdates //停用日期
            }
            if (this.$refs.publicForm.submitForm()) {
                this.saveForm(data);
            } else {
                console.log("error");
            }
        },

        // 保存
        saveForm(data) {
            this.isLock = true
            updateQualityDuty(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.isLock = false
                        this.visible = false;
                        this.$emit("refreshList");
                        this.$message.success("修改成功");

                    } else {
                        this.isLock = false
                        this.$message.error(res.msg);
                        console.log("接口报错");
                    }
                })
                .catch((error) => {
                    console.log("拌合站设置-新增）", error);
                });

        },
    },
};